﻿@model HZYProject.Domain.Question
@{var list = ViewBag.Names as List<HZYProject.Domain.Chapter>;}
<style>
    .red {
        color: red
    }
</style>

<div class="layer-edit" style="padding:10px">
    <form id="formEdit" class="layui-form" action="" onsubmit="return false">
        <input type="hidden" name="QuestionID" value="@Model.QuestionID" />
        <div class="layui-form-item">
            <label class="layui-form-label">所属章节<label class="red">*</label></label>
            <div class="layui-input-inline">
                <select id="ChapterID" name="ChapterID" lay-search="" lay-verify="required">
                    <option value="">--全部--</option>
                    @{
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (Model.ChapterID == list[i].ChapterID)
                            {
                                <option value="@list[i].ChapterID" selected>@list[i].Title</option>
                            }
                            else
                            {
                                <option value="@list[i].ChapterID">@list[i].Title</option>
                            }
                        }
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型<label class="red">*</label></label>
            <div class="layui-input-block">
                @{
                    if (Convert.ToInt32(Model.TypeName) == 1)
                    {
                        <input type="radio" name="typeName" value="1" title="单选题" checked="">
                        <input type="radio" name="typeName" value="2" title="多选题">
                        <input type="radio" name="typeName" value="3" title="填空题">
                        <input type="radio" name="typeName" value="4" title="判断题">
                        <input type="radio" name="typeName" value="5" title="拖拽题">
                        <input type="radio" name="typeName" value="6" title="排序题">
                    }
                    else if (Convert.ToInt32(Model.TypeName) == 2)
                    {
                        <input type="radio" name="typeName" value="1" title="单选题">
                        <input type="radio" name="typeName" value="2" title="多选题" checked="">
                        <input type="radio" name="typeName" value="3" title="填空题">
                        <input type="radio" name="typeName" value="4" title="判断题">
                        <input type="radio" name="typeName" value="5" title="拖拽题">
                        <input type="radio" name="typeName" value="6" title="排序题">
                    }
                    else if (Convert.ToInt32(Model.TypeName) == 3)
                    {
                        <input type="radio" name="typeName" value="1" title="单选题">
                        <input type="radio" name="typeName" value="2" title="多选题">
                        <input type="radio" name="typeName" value="3" title="填空题" checked="">
                        <input type="radio" name="typeName" value="4" title="判断题">
                        <input type="radio" name="typeName" value="5" title="拖拽题">
                        <input type="radio" name="typeName" value="6" title="排序题">
                    }
                    else if (Convert.ToInt32(Model.TypeName) == 4)
                    {
                        <input type="radio" name="typeName" value="1" title="单选题">
                        <input type="radio" name="typeName" value="2" title="多选题">
                        <input type="radio" name="typeName" value="3" title="填空题">
                        <input type="radio" name="typeName" value="4" title="判断题" checked="">
                        <input type="radio" name="typeName" value="5" title="拖拽题">
                        <input type="radio" name="typeName" value="6" title="排序题">
                    }
                    else if (Convert.ToInt32(Model.TypeName) == 5)
                    {
                        <input type="radio" name="typeName" value="1" title="单选题">
                        <input type="radio" name="typeName" value="2" title="多选题">
                        <input type="radio" name="typeName" value="3" title="填空题">
                        <input type="radio" name="typeName" value="4" title="判断题">
                        <input type="radio" name="typeName" value="5" title="拖拽题" checked="">
                        <input type="radio" name="typeName" value="6" title="排序题">
                    }
                    else if (Convert.ToInt32(Model.TypeName) == 6)
                    {
                        <input type="radio" name="typeName" value="1" title="单选题">
                        <input type="radio" name="typeName" value="2" title="多选题">
                        <input type="radio" name="typeName" value="3" title="填空题">
                        <input type="radio" name="typeName" value="4" title="判断题">
                        <input type="radio" name="typeName" value="5" title="拖拽题">
                        <input type="radio" name="typeName" value="6" title="排序题" checked="">
                    }
                }
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">建议分值<label class="red">*</label></label>
            <div class="layui-input-block">
                @{
                    if (Model.Score == 1)
                    {
                        <input type="radio" name="score" value="1" title="1分" checked="">
                        <input type="radio" name="score" value="2" title="2分">
                        <input type="radio" name="score" value="3" title="3分">
                    }
                    else if (Model.Score == 2)
                    {
                        <input type="radio" name="score" value="1" title="1分">
                        <input type="radio" name="score" value="2" title="2分" checked="">
                        <input type="radio" name="score" value="3" title="3分">
                    }
                    else if (Model.Score == 3)
                    {
                        <input type="radio" name="score" value="1" title="1分">
                        <input type="radio" name="score" value="2" title="2分">
                        <input type="radio" name="score" value="3" title="3分" checked="">
                    }
                }
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">题目<label class="red">*</label></label>
            <div class="layui-card-body">
                <textarea name="Title" id="edit" cols="30" rows="10">@Model.Title</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">解析</label>
            <div class="layui-input-block">
                <input id="Content" name="Content" value="@Model.Content" maxlength="100" class="layui-input" />
            </div>
        </div>
        @* 没写接下来的选项和答案 *@


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="pear-btn pear-btn-primary pear-btn-sm" lay-submit lay-filter="formDemo">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
</div>
@section script{
    <script>
        layui.use(['form', 'jquery', 'tinymce'], function () {
            var form = layui.form;
            let $ = layui.jquery;
            let tinymce = layui.tinymce;

            var edit = tinymce.render({
                elem: "#edit",
                height: 400
            });

            form.on('submit(formDemo)', function (data) {
                var str = $("#formEdit").serialize();
                $.post("/Question/edit", str, function (res) {
                    if (res.success) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        }, function () {
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        });
                    }
                    else
                        layer.msg("修改失败：" + res.msg, {
                            icon: 2,
                            time: 1000
                        });
                }, "json");
                return false;
            });
        });


    </script>
}